package www.lagou.dao;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import www.lagou.entity.Phone;
import www.lagou.utils.DruidUtil;

import java.sql.SQLException;
import java.util.List;

public class PhoneDao {


    public List<Phone> findPhoneBypriceAndprodate(Phone phone) throws SQLException {
        QueryRunner qr = new QueryRunner(DruidUtil.getDataSource());

        String sql = "select * from phone where price >? and prodate < ?";

        List<Phone> phoneList = qr.query(sql, new BeanListHandler<Phone>(Phone.class), phone.getPrice(), phone.getProdate());

        return phoneList;
    }

    public Phone findPhoneByColor(String color) throws SQLException {
        QueryRunner qr = new QueryRunner(DruidUtil.getDataSource());

        String sql = "select * from phone where color = ?";

        Phone phone = qr.query(sql, new BeanHandler<Phone>(Phone.class), color);
        return phone;
    }
}
